package com.bj58.groupbuy.action.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.bj58.groupbuy.action.db.CommonDao;
import com.bj58.groupbuy.action.db.DBConfig;
import com.bj58.groupbuy.action.model.UploadDocInfo;
import com.bj58.groupbuy.action.service.UploadDocInfoService;
import com.bj58.groupbuy.service.impl.BaseService;
import com.bj58.groupbuy.wf.page.Paginate;

public class UploadDocInfoServiceImpl extends BaseService<UploadDocInfo> implements UploadDocInfoService{
	private CommonDao comDao = new CommonDao();
	
	@Override
	public int saveDocInfo(UploadDocInfo docInfo) throws Exception {
		return (Integer) save(docInfo);
	}

	@Override
	public List<UploadDocInfo> getAllDocInfo() throws Exception {
		return getGenericDao().find(UploadDocInfo.class,"*","","");
	}

	@Override
	public Paginate<UploadDocInfo> getListByPage(String condition,int pageIndex,int pageSize) throws Exception {
		Paginate<UploadDocInfo> rsList= getGenericDao().findForPage(UploadDocInfo.class, condition, "*", pageIndex, pageSize, " uploadTime desc");
		if(null != rsList)
			return rsList;
		
		return null;
	}

	@Override
	public UploadDocInfo getBySaveName(String saveName) throws Exception {
		List<UploadDocInfo> rsList = getGenericDao().find(UploadDocInfo.class,"*", "saveName="+saveName, "");
		if(null != rsList && !rsList.isEmpty() )
			return rsList.get(0);
		return null;
	}

	@Override
	public List<String> getAllFileCate1() throws Exception {
		String sql = "select distinct fileCate1 from upload_doc_info where state=1 and fileCate1 is not null and fileCate1 != ''";
		
		return comDao.searchReturnStrings(sql, DBConfig.db_68_bi_sys.getIntType());
	}

	@Override
	public List<String> getAllFileCate2(String cate1) throws Exception {
		
		String sql = "select distinct fileCate2 from upload_doc_info where state=1 and fileCate2 is not null and fileCate2 != ''";
		if(StringUtils.isBlank(cate1)){
			sql += " and (fileCate1 is null or fileCate1 = '')";
		}else{
			sql += " and fileCate1 ='"+cate1+"'";
		}
		return comDao.searchReturnStrings(sql, DBConfig.db_68_bi_sys.getIntType());
	}
	
}
